package com.haixiaoke.saas.enterprise.house.controller;

import javax.servlet.http.HttpServletResponse;

import com.haixiaoke.saas.common.annotation.RepeatSubmit;
import com.haixiaoke.saas.common.annotation.TenantScope;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.tenant.TenantContext;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.house.domain.HouseSweep;
import com.haixiaoke.saas.house.service.IHouseSweepService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 打扫记录Controller
 *
 * @author xiaolong
 * @date 2024-05-11
 */
@RestController
@RequestMapping("/enterprise/house/sweep")
public class EnterpriseHouseSweepController extends BaseController {
    @Autowired
    private IHouseSweepService houseSweepService;

    /**
     * 查询打扫记录列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:sweep:list')")
    @GetMapping("/list")
    @TenantScope
    public TableDataInfo list(HouseSweep houseSweep) {
        startPage();
        houseSweep.setTenantId(TenantContext.getTenantId());
        List<HouseSweep> list = houseSweepService.selectHouseSweepList(houseSweep);
        return getDataTable(list);
    }

    /**
     * 导出打扫记录列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseSweep houseSweep) {
        List<HouseSweep> list = houseSweepService.selectHouseSweepList(houseSweep);
        ExcelUtil<HouseSweep> util = new ExcelUtil<HouseSweep>(HouseSweep.class);
        util.exportExcel(response, list, "打扫记录数据");
    }

    /**
     * 获取打扫记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:sweep:query')")
    @GetMapping(value = "/{houseSweepId}")
    public AjaxResult getInfo(@PathVariable("houseSweepId") String houseSweepId) {
        return success(houseSweepService.selectHouseSweepByHouseSweepId(houseSweepId));
    }

    /**
     * 新增退换打扫记录
     */
    @PreAuthorize("@ss.hasPermi('enterprise:sweep:add')")
    @PostMapping
    @TenantScope
    @RepeatSubmit
    public AjaxResult add(@RequestBody HouseSweep houseSweep) {
        Long userId = getUserId();
        houseSweep.setOperatorId(userId);
        houseSweep.setTenantId(TenantContext.getTenantId());
        return toAjax(houseSweepService.insertHouseSweepInfo(houseSweep));
    }


    /**
     * 新增日常打扫记录
     */
    @PreAuthorize("@ss.hasPermi('enterprise:sweep:add')")
    @PostMapping("/routineSweep")
    @TenantScope
    @RepeatSubmit
    public AjaxResult routineSweep(@RequestBody HouseSweep houseSweep) {
        Long userId = getUserId();
        houseSweep.setOperatorId(userId);
        houseSweep.setTenantId(TenantContext.getTenantId());
        return toAjax(houseSweepService.routineSweep(houseSweep));
    }

    /**
     * 指定打扫人员
     */
    @PreAuthorize("@ss.hasPermi('enterprise:sweep:edit')")
    @PutMapping
    @TenantScope
    @RepeatSubmit
    public AjaxResult edit(@RequestBody HouseSweep houseSweep) {
        Long userId = getUserId();
        houseSweep.setOperatorId(userId);
        return toAjax(houseSweepService.updateHouseSweep(houseSweep));
    }


    /**
     * 更换打扫人员
     */
    @PreAuthorize("@ss.hasPermi('enterprise:sweep:change')")
    @PutMapping("/change")
    @TenantScope
    @RepeatSubmit
    public AjaxResult change(@RequestBody HouseSweep houseSweep) {
        Long userId = getUserId();
        houseSweep.setOperatorId(userId);
        return toAjax(houseSweepService.changeHouseSweep(houseSweep));
    }

    /**
     * 删除打扫记录
     */
    @PreAuthorize("@ss.hasPermi('enterprise:sweep:remove')")
    @DeleteMapping("/{houseSweepIds}")
    @TenantScope
    @RepeatSubmit
    public AjaxResult remove(@PathVariable String[] houseSweepIds) {
        return toAjax(houseSweepService.deleteHouseSweepByHouseSweepIds(houseSweepIds));
    }
}
